package main

import "fmt"

func main() {
	//learnSwitchCase()
	//typeSwitch()
	//forTest()
	//whileTest()
	//doWhileTest()
	//printMultiplicationTable()
	gotoTest()
}

func learnSwitchCase() {
	var num int
	fmt.Println("请输入一个数字：")
	fmt.Scanln(&num)
	switch {
	case num%2 == 0 && num%3 == 0:
		fmt.Println(num, "% 6 == 0")
	case num%9 == 0:
		fmt.Println(num, "% 9 == 0")
	case num%100 == 0:
		fmt.Println(num, "% 100 == 0")
		fallthrough
	case num > 400:
		fmt.Println(num, "> 400")
	default:
		fmt.Println(num)
	}

}

func typeSwitch() {
	var x interface{}
	var y float64 = 10.0
	x = y
	switch x.(type) {
	case nil:
		fmt.Println("nil")
	case int:
		fmt.Println("int")
	case float32:
		fmt.Println("float32")
	case float64:
		fmt.Println("float64")
	case string:
		fmt.Println("string")
	case bool:
		fmt.Println("bool")
	default:
		fmt.Println("unknown type")
	}
}

func forTest() {
	// for循环的四种写法

	for i := 0; i < 10; i++ {
		fmt.Println("testing", i)
	}

	fmt.Println("--------------------------------")

	var i int = 0
	for i < 10 {
		fmt.Println("testing", i)
		i++
	}

	fmt.Println("--------------------------------")

	i = 0
	for {
		fmt.Println("testing", i)
		i++
		if i >= 10 {
			break
		}
	}

	fmt.Println("--------------------------------")

	var str string = "adafv"

	for index, val := range str {
		fmt.Printf("index = %d, val = %c\n", index, val)
	}
}

func whileTest() {
	var i int = 1
	for {
		if i >= 10 {
			break
		}
		fmt.Println("while test", i)
		i++
	}
}

func doWhileTest() {
	var i int = 1
	for {
		fmt.Println("do while test", i)
		i++
		if i >= 0 {
			break
		}
	}
}

func printMultiplicationTable() {
	for i := 1; i < 10; i++ {
		for j := 1; j <= i; j++ {
			fmt.Printf("%d * %d = %d   ", i, j, i*j)
		}
		fmt.Printf("\n")
	}
}

func gotoTest() {
	// 用的比较少
	for i := 1; i < 6; i++ {
		fmt.Println(i)
		if i >= 6 {
			goto label
		}
	}
label:
	fmt.Println("stop")
}
